from pptx import Presentation
from pptx.chart.data import CategoryChartData, ChartData

def page1():
    print('processing page1')
    slide = slides[0]
    shape1 = slide.shapes[0]
    shape2 = slide.shapes[1]
    p1 = shape1.text_frame.paragraphs[0]
    p1.runs[0].text = '李四的投资组织报表'
    shape2.text_frame.paragraphs[0].runs[1].text = '2020-12-31'

def page2():
    sd = slides[1]
    total = sd.shapes[2]
    summary = sd.shapes[6]
    total.text_frame.paragraphs[0].runs[0].text = '888888.88'
    summary.text_frame.paragraphs[0].runs[0].text = '测试总结，测试总结，测试总结'

    #资产净值表格
    table = sd.shapes[3].table
    for i in range(1, 7):
        table.cell(i, 0).text = '2020-8-31'
        table.cell(i, 1).text = '9999999'
        table.cell(i, 2).text = '6789'  

    #资产净值的折线图
    chart = sd.shapes[5].chart
    #准备数据
    chart_data = ChartData()
    chart_data.categories = ['1月', '2月', '3月', '4月', '5月', '6月']
    chart_data.add_series('净值',    (32.2, 28.4, 34.7, 34.7, 36.7, 38.7))
    chart.replace_data(chart_data)

def page3():
    slide = slides[2]
    table = slide.shapes[1].table
    for i in range(1, 11):
        table.cell(i, 0).text = 'BABA'
        table.cell(i, 1).text = '3456.88'
        table.cell(i, 2).text = '8' 
    
    #资产类别表格
    table = slide.shapes[4].table
    for i in range(1, 5):
        table.cell(i, 0).text = '股票'
        table.cell(i, 1).text = '20'
    
    #资产类别饼图
    chart = slide.shapes[5].chart
    chart_data = ChartData()
    chart_data.categories = ['权益类', '债券类', '货币类', '其他']
    chart_data.add_series('Series 1', (0.261, 0.324, 0.180, 0.235))
    chart.replace_data(chart_data)

def page4():
    text = '''
    这是第一段

    这是第二段

    第三段
    '''
    slide = slides[3]
    shape = slide.shapes[1]
    tf = shape.text_frame
    tf.text = text

ppt = Presentation('客户报表.pptx')
slides = ppt.slides
page1()
page2()
page3()
page4()
ppt.save('李四.pptx')